<?php

namespace App\Http\Controllers;

use App\Models\Expert;
use App\Models\Video;
use Illuminate\Http\Request;

class FrontController extends Controller
{
    public function index(){
        //获取专家前两条
        $oExperts = Expert::take(2)->get();
        //获取录播前三条
        $oVideos = Video::where('type','0')->orderBy('end_at','asc')->take(3)->get();
        //先获取直播取出最近的直播
        $cnt = Video::where('type','1')->count();
        if($cnt>0){
            $oVideo = Video::where('type','1')->orderBy('start_at','asc')->first();
            return view('front.index')
                ->with('cnt',$cnt)
                ->with('oVideo',$oVideo)
                ->with('oExperts',$oExperts)
                ->with('oVideos',$oVideos);
        }
        return view('front.index')
            ->with('cnt',$cnt)
            ->with('oExperts',$oExperts)
            ->with('oVideos',$oVideos);

    }//首页
    public function class(){
        $cnt = Video::where('type','1')->count();
        if($cnt>0){
            $oVideo = Video::where('type','1')->orderBy('start_at','asc')->first();
            return view('front.jiangtang')
                ->with('cnt',$cnt)
                ->with('oVideo',$oVideo);
        }
        return view('front.jiangtang')
            ->with('cnt',$cnt);
    }
    public function expert(){
        $oExpert = Expert::paginate(9);
        return view("front.fengcai")
            ->with('oExpert',$oExpert);
    }
    public function video(){
        $oVideos = Video::paginate(9);
        return view('front.shipin')
            ->with('oVideos',$oVideos);
    }
    public function expertShow($id){
        $expert=Expert::find($id);
        $oExpert=Expert::where('id','!=',$id)->take(3)->get();//在专家列表里找和find找到不一样的3个expert
        return view('front.fengcai-show')
            ->with('oExpert',$oExpert)
            ->with('expert',$expert);
    }
    public function videoShow($id){
        $oVideo=Video::find($id);
        $otherVideo=Video::where('type',0)->where('id','!=',$id)->orderBy('start_at','desc')->first();
        return view('front.shipin-show')
            ->with('oVideo',$oVideo)
            ->with('otherVideo',$otherVideo);
    }
}
